
{% import xutils.textutil as textutil %}
{% init parent_path = None %}

{% include note/component/css/gallery_css.html %}

<div class="card">
    {% include note/component/view_header.html %}
</div>

<div class="card">
    {% include note/component/note_path.html %}
</div>

<div class="card btn-line-height">
    {% include note/component/view_header_tag.html %}
</div>

<div class="card">
    <!-- 上传文件组件 -->
    {% if file.creator == _user_name %} 
        {% include fs/mod_fs_upload.html %}
    {% end %}


    <div class="file-list">
        {% for item in filelist %}
            {# 隐藏文件 #}
            {% if item.name == "" %}
                {% continue %}
            {% end %}
            
            {% if xconfig.FS_HIDE_FILES and (item.name[0] == "." or item.name.endswith((".pyc", ".class"))) %}
                {% continue %}
            {% end %}

            {% if not item.name.startswith("._") %}
                <div class="gallery-item context-menu-one">
                    <div class="icon-box">
                        {% if item.type == "dir" %}
                            <img class="fs-icon" src="/static/image/folder2.png">
                        {% elif xutils.is_img_file(item.path) %}
                            <img class="x-photo" src="/data/files/{{quote(item.path)}}?mode=thumbnail" 
                                data-src="/data/files/{{quote(item.path)}}">
                        {% elif xutils.is_text_file(item.path) %}
                            <img class="fs-icon" src="/static/image/icon_txt.png">
                        {% else %}
                            <img class="fs-icon" src="/static/image/file2.png">
                        {% end %}
                    </div>
                </div>
            {% end %}
        {% end %}
    </div>
</div>

<script type="text/javascript">
$(function () {
    $("#noteIdInput").val("{{file.id}}");
    function updateSize() { 
        console.log("updateSize");
        var listWidth = $(".file-list").width();
        var photoWidth = 200;

        if (listWidth <= 400) {
            photoWidth = 100;
        }

        var cols = parseInt(listWidth / photoWidth);
        photoWidth = parseInt(listWidth / cols);

        $(".gallery-item").css("width", photoWidth);
        // 采用读写分离的方式，阅读和编辑使用两个不同的视图
    }

    updateSize();
    $(window).on("resize", updateSize);
})
</script>
